package org.goldfish.distributed_framework.registry;

import com.sun.net.httpserver.HttpServer;
import org.goldfish.distributed_framework.config.*;
import org.goldfish.distributed_framework.registry.handlers.*;

import java.io.IOException;
import java.net.InetSocketAddress;

public class RegistryServer {

    public static void start(RegistryConfig config) throws IOException {
        int port = config.port;
        HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
        server.createContext("/register", new RegisterHandler("/register"));
        server.createContext("/query", new QueryHandler("/query"));
        server.setExecutor(null);
        server.start();
        System.out.println("注册中心启动成功，端口: " + port);
    }
}
